package mediator.scala

import scala.swing._

trait Mediator {
  self: MediatorFrame =>
  def book() {
    btnView.enabled = true
    btnBook.enabled = false
    btnSearch.enabled = true
    show.text = "booking..."
  }

  def view() {
    btnView.enabled = false
    btnBook.enabled = true
    btnSearch.enabled = true
    show.text = "viewing..."

  }

  def search() {
    btnSearch.enabled = false
    btnView.enabled = true
    btnBook.enabled = true
    show.text = "searching..."
  }
}


class MediatorFrame extends Frame with Mediator {
  val show = new Label("Just start...")
  val btnView = Button("View"){
    view()
  }
  val btnSearch = Button("Search"){
    search()
  }
  val btnBook = Button("Book"){
    book()
  }

  val panel = new FlowPanel {
    contents += btnView
    contents += btnSearch
    contents += btnBook
  }
  val contentPane = new BorderPanel {
    add(show, BorderPanel.Position.North)
    add(panel, BorderPanel.Position.South)
  }

  contents = contentPane
}

object MediatorDemo extends App {
  val frame = new MediatorFrame
  frame.size = new Dimension(400, 200)
  frame.visible = true
}
